Creating a 1D Array


In [2]:
import numpy as np

an_array = np.array([1,3,5,7, 9])

print(an_array)

print(type(an_array))


[1 3 5 7 9]
<class 'numpy.ndarray'>

In [4]:
print(an_array.shape)


(5,)

Creating 2D arrays


In [7]:
twoD_array = np.array([[11,12,13], [21,22,23]])

print(twoD_array)
print(twoD_array.shape)


[[11 12 13]
 [21 22 23]]
(2, 3)

Many ways to create nd arrays


In [17]:
ex1 = np.zeros([2,2])
print(ex1)


[[ 0.  0.]
 [ 0.  0.]]

In [18]:
ex2 = np.full((2,2), 9)
print(ex2)


[[9 9]
 [9 9]]

In [22]:
ex3 = np.eye(3,2)
print(ex3)


[[ 1.  0.]
 [ 0.  1.]
 [ 0.  0.]]

In [23]:
ex4 = np.ones((1,2))
print(ex4)


[[ 1.  1.]]

In [24]:
ex5 = np.random.random((2,2))
print(ex5)


[[ 0.6159929   0.32933592]
 [ 0.25075797  0.28710947]]